package com.wlyuan.open.domain.source.constants;

import com.wlyuan.utils.BaseEnum;
import com.wlyuan.utils.EnumUtils;

import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 * description 是否自动委托对账枚举
 */
public enum AutoBalanceEnum implements BaseEnum {
    OPEN(0, true, "开启"),
    CLOSE(1, false, "关闭");

    private static final Map<Integer, AutoBalanceEnum> MAP = EnumUtils.map(AutoBalanceEnum.values());
    private final int value;
    private final boolean newValue;
    private final String name;

    AutoBalanceEnum(int value, boolean newValue, String name) {
        this.value = value;
        this.newValue = newValue;
        this.name = name;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Integer getValue() {
        return this.value;
    }

    public boolean getNewValue() {
        return this.newValue;
    }

    public static AutoBalanceEnum fromValue(Integer value) {
        return Optional.ofNullable(value).map(AutoBalanceEnum::get).orElse(CLOSE);
    }

    private static AutoBalanceEnum get(Integer val) {
        return MAP.get(val);
    }
}
